<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Api_NotificationController extends Zend_Rest_Controller
{
	public function init()
	{
		$this->_helper->viewRenderer->setNoRender(true);
	}


	public function deleteAction() {
                try{
			$notification_id = $this->_getParam('id');
			if($notification_id != ""){
				$notification_mapper = new Api_Model_NotificationMapper();
				$notification_mapper->deleteNotification($notification_id);

				throw new Exception(json_encode(array('meta' => 'OK')),200);
			} else{
				throw new Exception(json_encode(array('meta' => 'Bad request')),400);
			}

		}catch(Exception $e){
			$this->getresponse()->appendBody($e->getMessage());
			$this->getResponse()->setHttpResponseCode($e->getCode());
		}
	}

	public function getAction() {
                try{
			$notification_mapper = new Api_Model_NotificationMapper();
			$notification_id = $this->_getParam('id');

			if ($notification_id != NULL){

				$notification_mapper->readNotification($notification_id);
				throw new Exception(json_encode(array('meta' => 'OK')),200);
			} else {
				throw new Exception(json_encode(array('meta' => 'Bad request')),400);
			}

		}catch(Exception $e){
			$this->getresponse()->appendBody($e->getMessage());
			$this->getResponse()->setHttpResponseCode($e->getCode());
		}
	}

	public function headAction() {

	}

	public function indexAction() {
		try{
			$notification_mapper = new Api_Model_NotificationMapper();
			$user_id = $this->_getParam('param1');

			if ($user_id != NULL){

				$notification = $notification_mapper->getAllNotification($user_id);
				$this->getresponse()->appendBody(json_encode($notification));
				$this->getResponse()->setHttpResponseCode(200);
			} else {
				throw new Exception(json_encode(array('meta' => 'Bad request')),400);
			}

		}catch(Exception $e){
			$this->getresponse()->appendBody($e->getMessage());
			$this->getResponse()->setHttpResponseCode($e->getCode());
		}
	}

	public function getusermessageAction() {

	}

	public function postAction() {

	}

	public function putAction() {

	}
}
